import {
  defineStore
} from "pinia";
import {
  reqLogout
} from '@/api/login.js'

import {
  constantRoute
} from '@/router/routes.js'
export default defineStore("login", {
  state: () => {
    return {
      token: localStorage.getItem('token'),
      luser: localStorage.getItem('luser'),
      menulist: constantRoute,
    };
  },
  actions: {
    // 用户登录
    async userLogin(login_data) {
      let result = await reqLogout(login_data)
      if (result.code == 1) {
        this.token = result.data.token
        this.luser = result.data.luser
        localStorage.setItem('token', result.data.token)
        localStorage.setItem('luser', JSON.stringify(result.data.luser))
        return 'ok'
      } else {
        return Promise.reject(new Error(result.msg))
      }
    }
  },
  getters: {},
});
